/**
 *
 * 建造工具
 * @author 
 *
 */
class UnitTool extends egret.Sprite {
    
    private bm: egret.Bitmap;
    private icon: UnitIcon;
    private gold: number;
    protected objTouch: any;
    protected iconArr:UnitIcon[]=[];
    
    //根据当前选中对象类型生成建造工具
	public constructor(gold:number) {
        super();
        this.cacheAsBitmap = true;
        
        //当前关卡拥有金钱
        this.gold = gold;
        //生成建造工具ICON
        this.createTools();
	}
	
	/**根据当前选中对象类型生成建造工具*/
	private createTools(){
    	
    	var unitArr:string[] = GuankaBase.instance.soldierArr;

        this.addIcon(unitArr[0],0,0);
        this.addIcon(unitArr[1],51,0);
        this.addIcon(unitArr[2],102,0);
        this.addIcon(unitArr[3],153,0);
        this.addIcon(unitArr[4],204,0);
        this.addIcon(unitArr[5],255,0);
        this.addIcon(unitArr[6],306,0);
        
	}
	
	/**建造一个icon*/
	private addIcon(type:string,x:number,y:number){
        this.icon = new UnitIcon(type,this.gold);
        this.icon.x = x;
        this.icon.y = y;
        this.icon.touchEnabled = true;
        this.icon.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.iconClickHandle,this);
        this.addChild(this.icon);
        if(type!="lock"){
            this.iconArr.push(this.icon);
        }

	}
	
	/**建造icon点击事件*/
	private iconClickHandle(e:egret.TouchEvent){
        var className = e.currentTarget.className;
        var price = e.currentTarget.price;
        if(e.currentTarget.is == false){
            e.currentTarget.is = true;
            return;
        }
        if(this.gold >= price)
        this.dispatchEvent(new ToolEvent(ToolEvent.BUILD_START,className,price));
	}
	
    public onEnterFrame(advancedtime: number) {
        for(var i = 0;i<this.iconArr.length;i++){
            this.iconArr[i].onEnterFrame(advancedtime);
        }


    }
}
